package com.cym.config;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
	@Resource
	private CommonInterceptor commonInterceptor;


	/**
	 * 跨域配置
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")//
				.allowedOriginPatterns("*")//
				.allowedMethods("POST", "GET", "OPTIONS")//
				.maxAge(3600)//
				.allowCredentials(true);//
	}

	/**
	 * 拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {

		registry.addInterceptor(commonInterceptor).addPathPatterns("/**") //
				.excludePathPatterns("/api/**")//
				.excludePathPatterns("/css/**")//
				.excludePathPatterns("/img/**")//
				.excludePathPatterns("/js/**")//
				.excludePathPatterns("/lib/**")//
				.excludePathPatterns("robots.txt")//
		;
	}


}
